// ActiveObject.cpp: implementation of the ActiveObject class.
//
//////////////////////////////////////////////////////////////////////

#include "../stdafx.h"
#include "ThreadObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CThreadObject::CThreadObject ()
: _isDying (0),
#pragma warning(disable: 4355) // 'this' used before initialized
  _thread (ThreadEntry, this)
#pragma warning(default: 4355)
{
}


void CThreadObject::Kill ()
{
    _isDying = true;
    FlushThread ();
    // Let's make sure it's gone
    _thread.WaitForDeath ();
}

// Thread Entry
DWORD WINAPI CThreadObject::ThreadEntry (void* pArg)
{
    CThreadObject * pActive = (CThreadObject *) pArg;
    pActive->InitThread ();
    pActive->Run ();
    return 0;
}
 
